package org.dromara.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.app.domain.vo.SkDarenBrowsingHistoryVo;
import org.dromara.app.domain.bo.SkDarenBrowsingHistoryBo;
import org.dromara.app.service.ISkDarenBrowsingHistoryService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 达人浏览记录
 *
 * @author Evacuation
 * @date 2024-08-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/SkDarenBrowsingHistory")
public class SkDarenBrowsingHistoryController extends BaseController {

    private final ISkDarenBrowsingHistoryService skDarenBrowsingHistoryService;

    /**
     * 查询达人浏览记录列表
     */
    @SaCheckPermission("app:SkDarenBrowsingHistory:list")
    @GetMapping("/list")
    public TableDataInfo<SkDarenBrowsingHistoryVo> list(SkDarenBrowsingHistoryBo bo, PageQuery pageQuery) {
        return skDarenBrowsingHistoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出达人浏览记录列表
     */
    @SaCheckPermission("app:SkDarenBrowsingHistory:export")
    @Log(title = "达人浏览记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SkDarenBrowsingHistoryBo bo, HttpServletResponse response) {
        List<SkDarenBrowsingHistoryVo> list = skDarenBrowsingHistoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "达人浏览记录", SkDarenBrowsingHistoryVo.class, response);
    }

    /**
     * 获取达人浏览记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:SkDarenBrowsingHistory:query")
    @GetMapping("/{id}")
    public R<SkDarenBrowsingHistoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(skDarenBrowsingHistoryService.queryById(id));
    }

    /**
     * 新增达人浏览记录
     */
    @SaCheckPermission("app:SkDarenBrowsingHistory:add")
    @Log(title = "达人浏览记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SkDarenBrowsingHistoryBo bo) {
        return toAjax(skDarenBrowsingHistoryService.insertByBo(bo));
    }

    /**
     * 修改达人浏览记录
     */
    @SaCheckPermission("app:SkDarenBrowsingHistory:edit")
    @Log(title = "达人浏览记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SkDarenBrowsingHistoryBo bo) {
        return toAjax(skDarenBrowsingHistoryService.updateByBo(bo));
    }

    /**
     * 删除达人浏览记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:SkDarenBrowsingHistory:remove")
    @Log(title = "达人浏览记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(skDarenBrowsingHistoryService.deleteWithValidByIds(List.of(ids), true));
    }
}
